package reflection.exercise;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:22954
 * Date:2024-04-17
 * Time:15:14
 */
public class Exercise2 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
        Class<?> cls = Class.forName("java.io.File");
        Constructor<?>[] constructors = cls.getDeclaredConstructors();
        for (Constructor<?> constructor : constructors) {
            System.out.println(constructor);
            //public java.io.File(java.lang.String)
            //public java.io.File(java.lang.String,java.lang.String)
            //public java.io.File(java.net.URI)
            //private java.io.File(java.lang.String,java.io.File)
            //private java.io.File(java.lang.String,int)
            //public java.io.File(java.io.File,java.lang.String)
        }
        Object o = cls.getDeclaredConstructor(String.class).newInstance("f:/Test/aaa.txt");
        Method createNewFile = cls.getDeclaredMethod("createNewFile");
        createNewFile.invoke(o);
    }
}
